<?php
function GetChanPostFields($tid,$sage,$txt,$pic,$password,$captcha)
{
	global $args;
	$data = array(
		"task" => "lulz",
		"board"=> $args['board'],
		"MAX_FILE_SIZE"=>204800,
		"jesuslol"=>"",
		"caturday"=>$txt,
		"cookies"=>"@".$pic,
		"gb2"=>"thread",
		"boottothehead"=>$password,
	);
	if ($tid)
		$data['parent']=$tid;
	if ($captcha)
		$data['captcha']=$captcha;
	return $data;
}
function GetChanDeleteFields($tids,$pass)
{
	$r = "";
	foreach ($tids as $i => $tid)
	{
		$r.="delete={$tid}&";
	}
	return $r."task=delete&password=$pass";
}
function GetChanPostUrl($board)
{
	return "http://lulz.ru/phakaba.php";
}
function GetChanDeleteUrl($board)
{
	return "http://lulz.ru/phakaba.php";
}
function GetChanCaptchaUrl($tid,$board)
{
	if ($tid)
		return "http://2ch.ru/cgi-bin/captcha.pl/{$board}?key=res{$tid}&dummy={$tid}";
	else
		return "http://2ch.ru/cgi-bin/captcha.pl/{$board}?key=mainpage&dummy=";
}
/*
* Checks whether it succeeded posting or not.
* 0 - retry	- no result, incorrect captcha, incorrect file etc.
* 1 - delay	- errors about time limit
* 2 - succeeded
*/
function CheckMakePostResult($r)
{
	if (preg_match("~<html><body><a href=\"/[\w]+/res/[\d]+\.[\w]+\">/[\w]+/res/[\d]+\.[\w]+\</a></body></html>~",$r['body'],$m))
	{
		return 2;
	}
	else
		return 0;
}
function GetBumpsList($r)
{
	$pattern = "~<a href=\"/[\w\d\-]+/res/([\d]+)\.html#i([\d]+)\">[^<]+</a>\s+</span>\&nbsp\;\s+<br />\s+<span class=\"filesize\">[^<]+<a target=\"_blank\" href=\"[^\"]+\">[^<]+</a>[^<]+<em>[^<]+</em>[^<]+</span>[^<]+<span class=\"thumbnailmsg\">[^<]+</span><br />[^<]*<a target=\"_blank\" href=\"[^\"]+\">[^<]+<img src=\"[^\"]+\" width=\"[^\"]+\" height=\"[^\"]+\" alt=\"[^\"]+\" class=\"thumb\" />[^<]+</a>[^<]+<blockquote>[^<]+<p>[^<]+<br/>[^\-]+- ([\d\w\_\-]+)</p><p>[^\;]+\;[^\;]+\; Thread ID ([\d]+)/([\d]+)</p>~";
	if(preg_match_all($pattern,$r['body'],$m))
	{
		$res = array();
		foreach ($m[1] as $i => $ptid)
		{
			$res[$m[2][$i]]=array("bump"=>$m[5][$i],"parent"=>$ptid);
		}
		return $res;
	}
	else
	return 0;
}
?>